# -*- coding: utf-8 -*-
# @Time    : 2019/5/18 16:57
# @Author  : awer
# @Email   : awer@awer.cn
# @File    : sign_helper.py
# @Software: PyCharm
import random

import math

import helper as hp


def get_rand_points():
    return random.randint(1, 5)


def get_sign_msg(jo):
    msg = jo.get('msg')
    if jo.get('suc'):
        msg = msg.replace('[消息头]', '[CQ:face,id=99]')
    else:
        msg = msg.replace('[消息头]', '[CQ:face,id=127]')
    return msg


def get_sign_msg_fail():
    msgs = ['[CQ:emoji,id=127776]您的签到受到宇宙射线干扰，未能成功\r\n[CQ:emoji,id=128073]不妨重试一下',
            '[CQ:emoji,id=128165]您的签到过于犀利，未被系统接受\r\n[CQ:emoji,id=128129]不妨重试一下',
            '[CQ:emoji,id=128513]签到未成功，再签到一次吧']
    return msgs[random.randint(0, len(msgs) - 1)]


def get_power(days):
    return 1 + int(math.log(days))


def get_welcome_msg(group_info, user_id):
    # [{'age': 0, 'area': '', 'card': '', 'card_changeable': False, 'group_id': 11549739, 'join_time': 1558110888, 'last_sent_time': 1558110888, 'level': '', 'nickname': '梁斗', 'role': 1, 'sex': 0, 'title': '', 'title_expire_time': 0, 'unfriendly': False, 'user_id': 5266172}, {'age': 28, 'area': '', 'card': '', 'card_changeable': False, 'group_id': 11549739, 'join_time': 0, 'last_sent_time': 1558109121, 'level': '', 'nickname': '柳随风', 'role': 3, 'sex': 0, 'title': '', 'title_expire_time': 0, 'unfriendly': False, 'user_id': 12066230}, {'age': 24, 'area': '', 'card': '', 'card_changeable': False, 'group_id': 11549739, 'join_time': 1556438106, 'last_sent_time': 1558140785, 'level': '', 'nickname': '老王', 'role': 2, 'sex': 0, 'title': '', 'title_expire_time': 0, 'unfriendly': False, 'user_id': 2038058507}]
    for user in group_info:
        if user['user_id'] == user_id:
            if user['sex'] == 0:
                sex = '帅哥'
            else:
                sex = '美女'
            msg = '\r\n' \
                  '[CQ:face,id=99]欢迎%s的加入！\r\n' \
                  '[CQ:face,id=21]您是第%d个群成员！' % (hp.str_at(user_id), sex, len(group_info))
            return msg


def get_bye_msg(user_info, op_user):
    if op_user is None or op_user == user_info['user_id']:
        msg = '%s(%s) 离开了本群\r\n' \
              '[CQ:face,id=107]江湖路远，有缘再会！' % (user_info['nickname'], user_info['user_id'])
    else:
        msg = '%s(%s) 被管理员（%s）移出本群\r\n' \
              '[CQ:face,id=169]相识不易，请规范言行！' % ((user_info['nickname']), user_info['user_id'], op_user)

    return msg
